package com.xpgk.mvc.deptStation;

import java.util.List;

import com.jfinal.log.Log;
import com.xpgk.dto.RenderBean;
import com.xpgk.dto.ZtreeNode;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.dept.DepartmentController;

public class DeptStationController extends BaseController {

	@SuppressWarnings("unused")
	private static final Log log = Log.getLog(DepartmentController.class);

	private DeptStationService deptStationService;
	
	private RenderBean result = new RenderBean();
	
	private String pIds; // 上级ids
	private String name; // 名称
	private int orderId; // 排序号
	private int level;// 级别

	public void index() {
		setAttr("curStationIds", getCUserStationIds());
		render("deptStation.html");
	}
	
	/**
	 * 岗位树形图
	 */
	public void treeData(){
		List<ZtreeNode> nodeList = deptStationService.childNodeData(getCxt(), ids, getCUserStationIds());
		renderJson(nodeList);
		
	}
	
	/**
	 * 添加岗位
	 */
	public void addStation(){
		ids = deptStationService.addStation(pIds, name, orderId, level);
		renderText(ids);
	}
	
	/**
	 * 更改岗位名称
	 */
	public void upStation(){
		deptStationService.updateStation(ids, name);
		renderText(ids);
	}
	
	/**
	 * 删除岗位
	 */
	public void delStation(){
		String result = deptStationService.deleteStation(ids);
		renderText(result);
	}
	
	/**
	 * 权限树形图
	 */
	public void rightTreeData(){
		String stationIds = getPara("stationIds", getCUserStationIds());
		List<ZtreeNode> nodeList = deptStationService.rightChildNodeData(getCxt(), ids, stationIds, getCUserStationIds());
		renderJson(nodeList);
	}
	
	/**
	 * 添加岗位权限
	 */
	public void addStationRight(){
		String stationIds = getPara("stationIds", getCUserStationIds());
		result = deptStationService.addStationRight(ids, stationIds, getCUserStationIds(), result);
		renderJson(result);
	}
	
	/**
	 * 删除岗位权限
	 */
	public void delStationRight(){
		String stationIds = getPara("stationIds", getCUserStationIds());
		result = deptStationService.delStationRight(ids, stationIds, getCUserStationIds(), result);
		renderJson(result);
		
	}

}
